
clear all
set more off, perm
capture log close
set maxvar 32767


******language
cd "C:\Users\hp\Dropbox\ziyan\Pair Point Estimates\Figures\plots_updated\l" // change location to the dropbox folder

use l_add, clear


preserve 
keep if var == "Kbar"
label var var_ub_ "95% CI"
label var add_pe "Minimum Skill Requirement"
twoway scatter add_pe level, sort lwidth(medthick) msize(medium) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick)   ///
	xlabel(2(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(,labsize(small)) ///
	title("Minimum Latent Language Skills Requirement by Level", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_kbar", replace)
	graph export "add_kbar.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ "95% CI"
label var add_pe "{&sigma}{sup:2}({&epsilon},l)"

replace var_lb_ = . if add_pe > 30
replace var_ub_ = . if add_pe > 30
replace add_pe = . if add_pe > 30

twoway scatter add_pe level, sort lwidth(medthick) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick) cmissing(n)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	title("Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Language)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variance with values over 30 are dropped to better visualize the estimates for the rest levels," "and their confidence intervals are not shown." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_sigma_30", replace)
	graph export "add_sigma_30.pdf", replace	
restore	
	
	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ "95% CI"
label var add_pe "{&sigma}{sup:2}({&epsilon},l)"
foreach i in add_pe var_lb_ var_ub_{
	replace `i' = ln(`i')
}


twoway scatter add_pe level, sort lwidth(medthick) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick) cmissing(n)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("log({&sigma}{sup:2}({&epsilon},l))", size(small)) ylabel(,labsize(small)) ///
	title("Log of Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Language)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in figures to better visualize the values for all difficulty levels." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_sigma", replace)
	graph export "add_sigma.pdf", replace	
restore	


**mul
**# mul_si

use "l_mul", clear
// replace var_ub_ = mul_pe + 1.96*var_sd_
// replace var_lb_ = mul_pe - 1.96*var_sd_
*kbar
preserve 
keep if var == "Kbar"
label var var_ub_ "95% CI"
label var mul_pe "Minimum Skill Requirement"
twoway scatter mul_pe level, sort lwidth(medthick) msize(medium) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(,labsize(small)) ///
	title("Minimum Latent Language Skills Requirement by Level", size(medium)) subtitle(Multiplicative Model with Skill Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_kbar", replace)
	graph export "mul_kbar.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ "95% CI"
label var mul_pe "{&sigma}{sup:2}({&epsilon},l)"
// foreach i in mul_pe var_lb_ var_ub_{
// 	replace `i' = ln(`i')
// }
replace var_lb_ = . if mul_pe > 30
replace var_ub_ = . if mul_pe > 30
replace mul_pe = . if mul_pe > 30

twoway scatter mul_pe level, sort lwidth(medthick) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick) cmissing(n)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	title("Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Language)", size(medium)) subtitle(Multiplicative Model with Skill Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variance with values over 30 are dropped to better visualize the estimates for the rest levels," "and their confidence intervals are not shown." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_sigma", replace)
	graph export "mul_sigma.pdf", replace	
restore	
	
	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ "95% CI"
label var mul_pe "{&sigma}{sup:2}({&epsilon},l)"
foreach i in mul_pe var_lb_ var_ub_{
	replace `i' = ln(`i')
}
// replace var_lb_ = . if mul_pe > 30
// replace var_ub_ = . if mul_pe > 30
// replace mul_pe = . if mul_pe > 30

twoway scatter mul_pe level, sort lwidth(medthick) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick) cmissing(n)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("log({&sigma}{sup:2}({&epsilon},l))", size(small)) ylabel(,labsize(small)) ///
	title("Log of Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Language)", size(medium)) subtitle(Multiplicative Model with Skill Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in figures to better visualize the values for all difficulty levels." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_logsigma", replace)
	graph export "mul_logsigma.pdf", replace	
restore	
	
preserve 
keep if var == "Delta"
label var var_ub_ "95% CI"
label var mul_pe "{&Delta}{sub:k}"
twoway scatter mul_pe level, sort lwidth(medium) msize(medium) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium)  ///
 	xlabel(3 4 5 6 7 8 9 10 11, labsize(small)) xmtick(, labsize(small)) ///
 	xtitle(Difficulty Level, size(small)) ytitle("{&Delta}{sub:k}", size(small)) ylabel(,labsize(small)) ///
 	title("Learning Task Component ({&Delta}{sub:k}) by Level (Language)", size(medium)) subtitle(Multiplicative Model with Skill Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
 	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Levels 1, 3, 4, 9 and 13 normalized to 1.", size(small) span)   ///
 	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
 	saving("mul_Delta", replace)
 	graph export "mul_Delta.pdf", replace	
restore	
	


**# add_wo

use l_add_wo_si, clear

preserve 
keep if var == "Kbar"
label var var_ub_ "95% CI"
label var add_pe "Minimum Skill Requirement"
twoway scatter add_pe level, sort lwidth(medthick) msize(medium) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick)   ///
	xlabel(2(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(,labsize(small)) ///
	title("Minimum Latent Language Skills Requirement by Level", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_kbar_wo", replace)
	graph export "add_kbar_wo.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ "95% CI"
label var add_pe "{&sigma}{sup:2}({&epsilon},l)"
// foreach i in mul_pe var_lb_ var_ub_{
// 	replace `i' = ln(`i')
// }
replace var_lb_ = . if add_pe > 30
replace var_ub_ = . if add_pe > 30
replace add_pe = . if add_pe > 30

twoway scatter add_pe level, sort lwidth(medthick) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick) cmissing(n)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	title("Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Language)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variance with values over 30 are dropped to better visualize the estimates for the rest levels," "and their confidence intervals are not shown." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_sigma_30_wo", replace)
	graph export "add_sigma_30_wo.pdf", replace	
restore	
	
	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ "95% CI"
label var add_pe "{&sigma}{sup:2}({&epsilon},l)"
foreach i in add_pe var_lb_ var_ub_{
	replace `i' = ln(`i')
}
// replace var_lb_ = . if mul_pe > 30
// replace var_ub_ = . if mul_pe > 30
// replace mul_pe = . if mul_pe > 30

twoway scatter add_pe level, sort lwidth(medthick) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick) cmissing(n)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("log({&sigma}{sup:2}({&epsilon},l))", size(small)) ylabel(,labsize(small)) ///
	title("Log of Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Language)", size(medium)) subtitle(Additive Model w/ Scale Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in figures to better visualize the values for all difficulty levels." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_sigma_wo", replace)
	graph export "add_sigma_wo.pdf", replace	
restore	


preserve 
keep if var == "Beta1"
label var var_ub_ "95% CI"
label var add_pe "{&beta}{sub:1}"
twoway connected add_pe level, sort lwidth(medthick) msize(medium) || line var_ub_ level, sort lcolor(gs11) lpattern(dash) lwidth(medthick) || line var_lb_ level, sort lcolor(gs11) lpattern(dash) lwidth(medthick)   ///
	xlabel(2(1)11, labsize(small)) xmtick(, labsize(small)) yline(1, lcolor(khaki) lwidth(medthick)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&beta}{sub:1}", size(small)) ylabel(,labsize(small)) ///
	title("Transformation Function Slope ({&beta}{sub:1,l}) by Level (Language)", size(large)) subtitle(Additive Model w/o Scale Invariance, size(medium)) legend(order(1 2) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
note("Note: The confidence interval is based on 1,000 iteration bootstrap." "All the children started from level 2 or above upon enrolling.", size(small) span)   ///	
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_beta1", replace)
	graph export "add_beta1.pdf", replace
restore	



**# mul_wo
use "l_mul_wo_si", clear
// replace var_ub_ = mul_pe + 1.96*var_sd_
// replace var_lb_ = mul_pe - 1.96*var_sd_
*kbar
preserve 
keep if var == "Kbar"
label var var_ub_ "95% CI"
label var mul_pe "Minimum Skill Requirement"
twoway scatter mul_pe level, sort lwidth(medthick) msize(medium) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(,labsize(small)) ///
	title("Minimum Latent Language Skills Requirement by Level", size(medium)) subtitle(Multiplicative Model without Skill Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_kbar_wo", replace)
	graph export "mul_kbar_wo.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ "95% CI"
label var mul_pe "{&sigma}{sup:2}({&epsilon},l)"
// foreach i in mul_pe var_lb_ var_ub_{
// 	replace `i' = ln(`i')
// }
replace var_lb_ = . if mul_pe > 30
replace var_ub_ = . if mul_pe > 30
replace mul_pe = . if mul_pe > 30

twoway scatter mul_pe level, sort lwidth(medthick) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick) cmissing(n)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	title("Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Language)", size(medium)) subtitle(Multiplicative Model without Skill Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variance with values over 30 are dropped to better visualize the estimates for the rest levels," "and their confidence intervals are not shown." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_sigma_wo", replace)
	graph export "mul_sigma_wo.pdf", replace	
restore	
	
	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ "95% CI"
label var mul_pe "{&sigma}{sup:2}({&epsilon},l)"
foreach i in mul_pe var_lb_ var_ub_{
	replace `i' = ln(`i')
}
// replace var_lb_ = . if mul_pe > 30
// replace var_ub_ = . if mul_pe > 30
// replace mul_pe = . if mul_pe > 30

twoway scatter mul_pe level, sort lwidth(medthick) msize(medium) cmissing(n) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medthick) cmissing(n)  ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("{&sigma}{sup:2}({&epsilon},l)", size(small)) ylabel(,labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle("log({&sigma}{sup:2}({&epsilon},l))", size(small)) ylabel(,labsize(small)) ///
	title("Log of Variances of Task Shocks ({&sigma}{sup:2}({&epsilon},l)) by Level (Language)", size(medium)) subtitle(Multiplicative Model without Skill Invariance, size(small)) legend(order(1 "{&sigma}{sup:2}({&epsilon},l)" 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in figures to better visualize the values for all difficulty levels." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_logsigma_wo", replace)
	graph export "mul_logsigma_wo.pdf", replace	
restore	
	

preserve 
keep if var == "Delta"
label var var_ub_ "95% CI"
label var mul_pe "{&Delta}{sub:k}"
twoway scatter mul_pe level, sort lwidth(medium) msize(medium) || rcap var_ub_ var_lb_ level, sort lcolor(gs10) lwidth(medium)  ///
 	xlabel(3 4 5 6 7 8 9 10 11, labsize(small)) xmtick(, labsize(small)) ///
 	xtitle(Difficulty Level, size(small)) ytitle("{&Delta}{sub:k}", size(small)) ylabel(,labsize(small)) ///
 	title("Learning Task Component ({&Delta}{sub:k}) by Level (Language)", size(medium)) subtitle(Multiplicative Model without Skill Invariance, size(small)) legend(order(1 2 "95% CI") row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
 	note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Levels 1, 3, 4, 9 and 13 normalized to 1.", size(small) span)   ///
 	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
 	saving("mul_Delta_wo", replace)
 	graph export "mul_Delta_wo.pdf", replace	
restore		
	
	
preserve 
 replace var_ub_ = mul_pe + 1.96*var_sd_
 replace var_lb_ = mul_pe - 1.96*var_sd_


keep if var == "Beta1"
label var var_ub_ "95% CI"
label var mul_pe "{&gamma}{sub:1}"
twoway connected mul_pe level, sort lwidth(medthick) msize(medium) || line var_ub_ level, sort lcolor(gs11) lpattern(dash) lwidth(medthick) || line var_lb_ level, sort lcolor(gs11) lpattern(dash) lwidth(medthick)   ///
	xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) yline(1, lcolor(khaki) lwidth(medthick))  ///
	xtitle(Difficulty Level, size(small)) ytitle("{&gamma}{sub:1,l}", size(small)) ylabel(,labsize(small)) ///
	title("Transformation Function Slope ({&gamma}{sub:1,l}) by Level (Language)", size(large)) subtitle(Multiplicative Model without Skill Invariance, size(medium)) legend(order(1 2) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The confidence interval is based on standard error." "All the children started from level 2 or above upon enrolling.", size(small) span)   ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_beta1_sd_wo", replace)
	graph export "mul_beta1_sd_wo.pdf", replace
restore	


		
	
**# lan eta_delta


use eta_delta_l_add, clear
label var m_eta_1_ "Fast"
label var m_eta_2_ "Normal"
label var m_eta_3_ "Slow"
label var ul_1_ "95% CI"
twoway connected m_eta_1_ level, sort lwidth(medthick) msize(medium) mc(navy) lcolor(navy) lpattern(dash)|| rcap ul_1_ ll_1_ level, sort lcolor(gs12) lwidth(medthick) || connected m_eta_2_ level, sort msize(medium) m(S) mc(olive) lcolor(olive)  lpattern(dash) || rcap ul_2_ ll_2_ level, sort lcolor(gs12) lwidth(medthick) || connected m_eta_3_ level, sort msize(medium) m(T) mc(orange) lcolor(orange)  lpattern(dash) || rcap ul_3_ ll_3_ level, sort lcolor(gs12) lwidth(medthick)  ///
	xlabel(2(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle({&delta}(l)E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title(Learning Component ({&delta}(l)E({&eta})) by Difficulty Level (Language), size(med)) subtitle(by Ability Group, size(medsmall)) legend(order(1 3 5 2 "95% CI") row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Fast group: the child can pass the first task at over 80% of the difficulty levels, and the average pass rate at that level is greater than 80%." "Normal group: the child doesn't pass the first task, and the pass rate is greater than 50%; or the child passes the first task, and the pass rate is" "between 50% and 80%. Slow group: the average pass rate is less than 50%.    2. 95% confidence intervals are shown for three groups." "3. All the children started from level 2 or above upon enrolling.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("add_deltaeta", replace)
	graph export "add_deltaeta.pdf", replace
	


use eta_delta_l_mul_vec, clear


label var m_eta_1_ "Fast"
label var m_eta_2_ "Normal"
label var m_eta_3_ "Slow"
label var ul_1_ "95% CI"
// twoway scatter m_eta_1_ level, sort lwidth(medthick) msize(medium) mc(navy) lcolor(navy) lpattern(dash)|| rcap ul_1_ ll_1_ level, sort lcolor(gs12) lwidth(medthick) || scatter m_eta_2_ level, sort msize(medium) m(S) mc(olive) lcolor(olive)  lpattern(dash) || rcap ul_2_ ll_2_ level, sort lcolor(gs12) lwidth(medthick) || scatter m_eta_3_ level, sort msize(medium) m(T) mc(orange) lcolor(orange)  lpattern(dash) || rcap ul_3_ ll_3_ level, sort lcolor(gs12) lwidth(medthick)  ///
twoway connected m_eta_1_ level, sort lwidth(medthick) msize(medium) mc(navy) lcolor(navy) lpattern(dash)|| rcap ul_1_ ll_1_ level, sort lcolor(gs12) lwidth(medthick) || connected m_eta_2_ level, sort msize(medium) m(S) mc(olive) lcolor(olive)  lpattern(dash) || rcap ul_2_ ll_2_ level, sort lcolor(gs12) lwidth(medthick) || connected m_eta_3_ level, sort msize(medium) m(T) mc(orange) lcolor(orange)  lpattern(dash) || rcap ul_3_ ll_3_ level, sort lcolor(gs12) lwidth(medthick)  ///
	xlabel(2(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle({&delta}(l)E({&eta}), size(small)) ylabel(,labsize(small)) ///
	title(Learning Component ({&delta}(l)E({&eta})) by Difficulty Level (Language), size(med)) subtitle(by Ability Group, size(medsmall)) legend(order(1 3 5 2 "95% CI") row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Fast group: the child can pass the first task at over 80% of the difficulty levels, and the average pass rate at that level is greater than 80%." "Normal group: the child doesn't pass the first task, and the pass rate is greater than 50%; or the child passes the first task, and the pass rate is" "between 50% and 80%. Slow group: the average pass rate is less than 50%.    2. 95% confidence intervals are shown for three groups." "3. All the children started from level 2 or above upon enrolling.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("mul_deltaeta", replace)
	graph export "mul_deltaeta.pdf", replace	
	

**# mul_vesc
use "l_mul_vesc", clear
// replace var_ub_ = mul_pe + 1.96*var_sd_
// replace var_lb_ = mul_pe - 1.96*var_sd_
*kbar
preserve
keep if var == "Kbar"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "Minimum Skill Requirement of vector model"
label var mul_pe_sc "Minimum Skill Requirement of scalar model"
twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash)), ///
       xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(, labsize(small)) ///
       title("Minimum Latent Language Skills Requirement by Level", size(medium)) ///
       subtitle(Multiplicative Model with Skill Invariance, size(small)) ///
       legend(order(1 "Minimum Skill Requirement - vector" 2 "Minimum Skill Requirement- scalar" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
       region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence interval is based on 1,000 iteration bootstrap." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
       ylabel(, labsize(medium))
graph save "mul_kbar_vesc", replace
graph export "mul_kbar_vesc.pdf", replace
restore	


preserve
keep if var == "Kbar"
label var mul_pe_ve "Minimum Skill Requirement of vector model"
label var mul_pe_sc "Minimum Skill Requirement of scalar model"
foreach i in mul_pe_ve var_lb_ve var_ub_ve{
	replace `i' = ln(`i')
}
foreach i in mul_pe_sc var_lb_sc var_ub_sc{
	replace `i' = ln(`i')
}
twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash)), ///
       xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(, labsize(small)) ///
       title("Log of Minimum Latent Language Skills Requirement by Level", size(medium)) ///
       subtitle(Multiplicative Model with Skill Invariance, size(small)) ///
       legend(order(1 "Minimum Skill Requirement - vector" 2 "Minimum Skill Requirement - scalar") row(2) size(small) nobox fcolor() ///
       region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: All the children started from level 2 or above upon enrolling." ///
       "The value at Level 2 is normalized to one.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
       ylabel(, labsize(medium))
graph save "mul_logkbar_vesc", replace
graph export "mul_logkbar_vesc.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "σ²(ε,l) of vector model"
label var mul_pe_sc "σ²(ε,l) of scalar model"
// foreach i in mul_pe var_lb_ var_ub_{
// 	replace `i' = ln(`i')
// }
replace var_lb_ve = . if mul_pe_ve > 30
replace var_ub_ve = . if mul_pe_ve > 30
replace mul_pe_ve = . if mul_pe_ve > 30
replace var_lb_sc = . if mul_pe_sc > 30
replace var_ub_sc = . if mul_pe_sc > 30
replace mul_pe_sc = . if mul_pe_sc > 30

foreach i in mul_pe_ve mul_pe_sc {
    replace `i' = ln(`i') if !missing(`i') & `i' <= 30
}

twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small) cmissing(n)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small) cmissing(n)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny) cmissing(n)) ///
       (rcap var_ub_sc var_lb_ve level, sort lcolor(red) lwidth(tiny) lpattern(dash) cmissing(n)), ///
	   xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle("σ²(ε,l)", size(small)) ylabel(, labsize(small)) ///
       title("Variances of Task Shocks (σ²(ε,l)) by Level (Language)", size(medium)) ///
       subtitle(Multiplicative Model with Skill Invariance, size(small)) ///
       legend(order(1 "σ²(ε,l) of vector model" 2 "σ²(ε,l) of scalar model" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
	   region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variance with values over 30 are dropped to better visualize the estimates for the rest levels," "and their confidence intervals are not shown." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
       ylabel(, labsize(medium))
graph save "mul_sigma_vesc", replace
graph export "mul_sigma_vesc.pdf", replace
restore	

	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "σ²(ε,l) of vector model"
label var mul_pe_sc "σ²(ε,l) of scalar model"
foreach i in mul_pe_ve var_lb_ve var_ub_ve{
	replace `i' = ln(`i')
}
foreach i in mul_pe_sc var_lb_sc var_ub_sc{
	replace `i' = ln(`i')
}
// replace var_lb_ = . if mul_pe > 30
// replace var_ub_ = . if mul_pe > 30
// replace mul_pe = . if mul_pe > 30

twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small) cmissing(n)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small) cmissing(n)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny) cmissing(n)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash) cmissing(n)), ///
	   xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle("σ²(ε,l)", size(small)) ylabel(, labsize(small)) ///
	   xtitle(Difficulty Level, size(small)) ytitle("log(σ²(ε,l))", size(small)) ylabel(,labsize(small)) ///
       title("Log of Variances of Task Shocks (σ²(ε,l)) by Level (Language)", size(medium)) ///
       subtitle(Multiplicative Model with Skill Invariance, size(small)) ///
       legend(order(1 "σ²(ε,l) of vector model" 2 "σ²(ε,l) of scalar model" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
       region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in figures to better visualize the values for all difficulty levels." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
       ylabel(, labsize(medium))
	   graph save "mul_logsigma_vesc", replace
       graph export "mul_logsigma_vesc.pdf", replace
restore	


preserve 
keep if var == "Delta"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "{&Delta}{sub:k} of vector model"
label var mul_pe_sc "{&Delta}{sub:k} of scalar model"
twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small) cmissing(n)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small) cmissing(n)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny) cmissing(n)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash) cmissing(n)), ///
	   xlabel(3 4 5 6 7 8 9 10 11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle("{&Delta}{sub:k}", size(small)) ylabel(, labsize(small)) ///
       title("Variances of Task Shocks ({&Delta}{sub:k}) by Level (Language)", size(medium)) ///
       subtitle(Multiplicative Model with Skill Invariance, size(small)) ///
       legend(order(1 "{&Delta}{sub:k} of vector model" 2 "{&Delta}{sub:k} of scalar model" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
	   region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Levels 1, 3, 4, 9 and 13 normalized to 1.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
 	   saving("mul_Delta_vesc", replace)
 	   graph export "mul_Delta_vesc.pdf", replace	
restore	


preserve 
keep if var == "Delta"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "{&Delta}{sub:k} of vector model"
label var mul_pe_sc "{&Delta}{sub:k} of scalar model"
foreach i in mul_pe_ve var_lb_ve var_ub_ve{
	replace `i' = ln(`i')
}
foreach i in mul_pe_sc var_lb_sc var_ub_sc{
	replace `i' = ln(`i')
}
twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small) cmissing(n)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small) cmissing(n)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny) cmissing(n)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash) cmissing(n)), ///
	   xlabel(3 4 5 6 7 8 9 10 11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle("{&Delta}{sub:k}", size(small)) ylabel(, labsize(small)) ///
       title("Log of Variances of Task Shocks ({&Delta}{sub:k}) by Level (Language)", size(medium)) ///
       subtitle(Multiplicative Model with Skill Invariance, size(small)) ///
       legend(order(1 "{&Delta}{sub:k} of vector model" 2 "{&Delta}{sub:k} of scalar model" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
	   region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Levels 1, 3, 4, 9 and 13 normalized to 1.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
 	   saving("mul_logDelta_vesc", replace)
 	   graph export "mul_logDelta_vesc.pdf", replace	
restore	

**# mu_wo_vesc	
use "l_mul_wo_si_vesc", clear
// replace var_ub_ = mul_pe + 1.96*var_sd_
// replace var_lb_ = mul_pe - 1.96*var_sd_
*kbar
preserve
keep if var == "Kbar"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "Minimum Skill Requirement of vector model"
label var mul_pe_sc "Minimum Skill Requirement of scalar model"
twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash)), ///
       xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(, labsize(small)) ///
       title("Minimum Latent Language Skills Requirement by Level", size(medium)) ///
       subtitle(Multiplicative Model without Skill Invariance, size(small)) ///
       legend(order(1 "Minimum Skill Requirement - vector" 2 "Minimum Skill Requirement - scalar" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
       region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence intervals are based on 1,000 iteration bootstrap." ///
       "All the children started from level 2 or above upon enrolling." ///
       "The value at Level 2 is normalized to one.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
       ylabel(, labsize(medium))
graph save "mul_kbar_wo_vesc", replace
graph export "mul_kbar_wo_vesc.pdf", replace
restore	

preserve
keep if var == "Kbar"
label var mul_pe_ve "Minimum Skill Requirement of vector model"
label var mul_pe_sc "Minimum Skill Requirement of scalar model"
foreach i in mul_pe_ve var_lb_ve var_ub_ve{
	replace `i' = ln(`i')
}
foreach i in mul_pe_sc var_lb_sc var_ub_sc{
	replace `i' = ln(`i')
}
twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash)), /// 
       xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle(Kbar, size(small)) ylabel(, labsize(small)) ///
       title("Log of Minimum Latent Language Skills Requirement by Level", size(medium)) ///
       subtitle(Multiplicative Model without Skill Invariance, size(small)) ///
       legend(order(1 "Minimum Skill Requirement - vector" 2 "Minimum Skill Requirement - scalar") row(2) size(small) nobox fcolor() ///
       region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: All the children started from level 2 or above upon enrolling." ///
       "The value at Level 2 is normalized to one.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
       ylabel(, labsize(medium))
graph save "mul_logkbar_wo_vesc", replace
graph export "mul_logkbar_wo_vesc.pdf", replace
restore


preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "σ²(ε,l) of vector model"
label var mul_pe_sc "σ²(ε,l) of scalar model"
// foreach i in mul_pe var_lb_ var_ub_{
// 	replace `i' = ln(`i')
// }
replace var_lb_ve = . if mul_pe_ve > 30
replace var_ub_ve = . if mul_pe_ve > 30
replace mul_pe_ve = . if mul_pe_ve > 30
replace var_lb_sc = . if mul_pe_sc > 30
replace var_ub_sc = . if mul_pe_sc > 30
replace mul_pe_sc = . if mul_pe_sc > 30

foreach i in mul_pe_ve mul_pe_sc {
    replace `i' = ln(`i') if !missing(`i') & `i' <= 30
}

twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small) cmissing(n)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small) cmissing(n)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny) cmissing(n)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash) cmissing(n)), ///
	   xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle("σ²(ε,l)", size(small)) ylabel(, labsize(small)) ///
       title("Variances of Task Shocks (σ²(ε,l)) by Level (Language)", size(medium)) ///
       subtitle(Multiplicative Model without Skill Invariance, size(small)) ///
       legend(order(1 "σ²(ε,l) of vector model" 2 "σ²(ε,l) of scalar model" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
	   region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence interval is based on 1,000 iteration bootstrap." "The variance with values over 30 are dropped to better visualize the estimates for the rest levels," "and their confidence intervals are not shown." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
       ylabel(, labsize(medium))
graph save "mul_sigma_wo_vesc", replace
graph export "mul_sigma_wo_vesc.pdf", replace
restore	
	
**log version
preserve 
keep if var != "Kbar" & var != "Delta"& var != "Beta1"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "σ²(ε,l) of vector model"
label var mul_pe_sc "σ²(ε,l) of scalar model"
foreach i in mul_pe_ve var_lb_ve var_ub_ve{
	replace `i' = ln(`i')
}
foreach i in mul_pe_sc var_lb_sc var_ub_sc{
	replace `i' = ln(`i')
}
// replace var_lb_ = . if mul_pe > 30
// replace var_ub_ = . if mul_pe > 30
// replace mul_pe = . if mul_pe > 30

twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small) cmissing(n)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small) cmissing(n)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny) cmissing(n)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash) cmissing(n)), ///
	   xlabel(3(1)11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle("σ²(ε,l)", size(small)) ylabel(, labsize(small)) ///
	   xtitle(Difficulty Level, size(small)) ytitle("log(σ²(ε,l))", size(small)) ylabel(,labsize(small)) ///
       title("Log of Variances of Task Shocks (σ²(ε,l)) by Level (Language)", size(medium)) ///
       subtitle(Multiplicative Model without Skill Invariance, size(small)) ///
       legend(order(1 "σ²(ε,l) of vector model" 2 "σ²(ε,l) of scalar model" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
       region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Log values are shown in figures to better visualize the values for all difficulty levels." "All the children started from level 2 or above upon enrolling." "The value at Level 2 is normalized to one.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
       ylabel(, labsize(medium))
	   graph save "mul_logsigma_wo_vesc", replace
       graph export "mul_logsigma_wo_vesc.pdf", replace
restore	


preserve 
keep if var == "Delta"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "{&Delta}{sub:k} of vector model"
label var mul_pe_sc "{&Delta}{sub:k} of scalar model"
twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small) cmissing(n)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small) cmissing(n)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny) cmissing(n)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash) cmissing(n)), ///
	   xlabel(3 4 5 6 7 8 9 10 11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle("{&Delta}{sub:k}", size(small)) ylabel(, labsize(small)) ///
       title("Variances of Task Shocks ({&Delta}{sub:k}) by Level (Language)", size(medium)) ///
       subtitle(Multiplicative Model without Skill Invariance, size(small)) ///
       legend(order(1 "{&Delta}{sub:k} of vector model" 2 "{&Delta}{sub:k} of scalar model" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
	   region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Levels 1, 3, 4, 9 and 13 normalized to 1.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
 	   saving("mul_Delta_wo_vesc", replace)
 	   graph export "mul_Delta_wo_vesc.pdf", replace	
restore	


preserve 
keep if var == "Delta"
label var var_ub_ve "95% CI of vector model"
label var var_ub_sc "95% CI of scalar model"
label var mul_pe_ve "{&Delta}{sub:k} of vector model"
label var mul_pe_sc "{&Delta}{sub:k} of scalar model"
foreach i in mul_pe_ve var_lb_ve var_ub_ve{
	replace `i' = ln(`i')
}
foreach i in mul_pe_sc var_lb_sc var_ub_sc{
	replace `i' = ln(`i')
}
twoway (scatter mul_pe_ve level, sort lwidth(medthick) msize(small) cmissing(n)) ///
       (scatter mul_pe_sc level, sort lcolor(red) lwidth(medthick) msize(small) cmissing(n)) ///
       (rcap var_ub_ve var_lb_ve level, sort lcolor(green) lwidth(tiny) cmissing(n)) ///
       (rcap var_ub_sc var_lb_sc level, sort lcolor(red) lwidth(tiny) lpattern(dash) cmissing(n)), ///
	   xlabel(3 4 5 6 7 8 9 10 11, labsize(small)) xmtick(, labsize(small)) ///
       xtitle(Difficulty Level, size(small)) ytitle("{&Delta}{sub:k}", size(small)) ylabel(, labsize(small)) ///
       title("Log of Variances of Task Shocks ({&Delta}{sub:k}) by Level (Language)", size(medium)) ///
       subtitle(Multiplicative Model without Skill Invariance, size(small)) ///
       legend(order(1 "{&Delta}{sub:k} of vector model" 2 "{&Delta}{sub:k} of scalar model" 3 "95% CI of vector model" 4 "95% CI of scalar model") row(2) size(small) nobox fcolor() ///
	   region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
       note("Note: The confidence interval is based on 1,000 iteration bootstrap." "Levels 1, 3, 4, 9 and 13 normalized to 1.", size(small) span)   ///
       graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
 	   saving("mul_logDelta_wo_vesc", replace)
 	   graph export "mul_logDelta_wo_vesc.pdf", replace	
restore	